package cn.net.dpi.minio.autoconfigure;

import cn.net.dpi.minio.support.MinioProp;
import cn.net.dpi.minio.support.MinioUtil;
import io.minio.MinioClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(MinioProp.class)
public class MinioConfig {

    @Bean
    @ConditionalOnMissingBean
    public MinioClient minioClient(MinioProp minioProp) {
        return MinioClient.builder()
                .endpoint(minioProp.getEndpoint())
                .credentials(minioProp.getAccessKey(), minioProp.getSecretKey())
                .build();
    }

    @Bean
    public MinioUtil minioUtil(MinioProp minioProp, MinioClient minioClient) {
        return new MinioUtil(minioProp, minioClient);
    }

}
